home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15637 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  50 lines

  1. Path: shellx.best.com!not-for-mail
  2. From: smurman@shellx.best.com (Scott Murman)
  3. Newsgroups: comp.lang.c++,comp.unix.solaris
  4. Subject: Working with Sun's CC-4.1
  5. Date: 6 Apr 1996 14:27:12 -0800
  6. Organization: Soga Technologies
  7. Distribution: inet
  8. Message-ID: <4k6r40$5qv@shellx.best.com>
  9. Reply-To: Scott Murman <smurman@best.com>
  10. NNTP-Posting-Host: shellx.best.com
  11.  
  12.  
  13. I've used gcc-2.7 as my C++ compiler for some time.  I've now got
  14. Sun's CC-4.1 to work with.  There are some problems with Sun's
  15. compiler that I'm trying to work around.  The first seems to be a
  16. restriction on the return type allowed when over loading
  17. operator->(). The second problem is that Sun hasn't implemented the
  18. draft standard revision whereby virtual methods can have a different
  19. return type in the derived class.  Here's an example code snippet that
  20. won't compile for me
  21.  
  22. template <class T>
  23. class Example {
  24.  
  25. public:
  26.     Example(const T& v) : _Value(v) {};
  27.  
  28. // this gives me "Error: Cannot have a return type of T* for operator->()"
  29.  
  30.     T* operator->(void) const {
  31.       return(&_Value);
  32.     }
  33.  
  34.         virtual Example* PointerMethod(void) const {
  35.           return(this);
  36.         }
  37.  
  38. private:
  39.    
  40.         T _Value;
  41. };
  42.  
  43. In a class derived from Example, PointerMethod is still required to
  44. return and Example* which is against the C++ draft standard.
  45.  
  46. Does anyone have methods to work around these problems/limitations?
  47. Have I messed up something in my compilation to get these problems?
  48.  
  49. Scott
  50.